package com.edevp.common.mybatis.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * ${DESCRIPTION}
 *
 * @author Lean
 * @create 2020-02-16 9:33 PM
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseEntity implements Serializable {
	private static final long serialVersionUID = 1L;
	@ApiModelProperty(value = "主键", name = "id")
	@TableId(value = "ID_", type = IdType.INPUT)
	protected String id;

	@ApiModelProperty(value = "创建人", name = "createUserId")
	@TableField(value = "CREATE_USER_ID_")
	protected String createUserId;

	@ApiModelProperty(value = "修改人", name = "updateUserId")
	@TableField(value = "UPDATE_USER_ID_")
	protected String updateUserId;

	@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
	@ApiModelProperty(value = "创建时间", name = "createTime")
	@TableField(value = "CREATE_TIME_")
	protected Date createTime;

	@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
	@ApiModelProperty(value = "修改时间", name = "updateTime")
	@TableField(value = "UPDATE_TIME_")
	protected Date updateTime;

	@ApiModelProperty(value = "备注", name = "remark")
	@TableField(value = "REMARK_")
	protected String remark;

	@ApiModelProperty(value = "排序", name = "sort")
	@TableField(value = "SORT_")
	protected Integer sort;

	@ApiModelProperty(value = "子组织", name = "comId")
	@TableField(value = "COM_ID_")
	private String comId;

	@ApiModelProperty(value = "组织", name = "subComId")
	@TableField(value = "SUB_COM_ID_")
	private String subComId;

	public void doBeforeInsert() {
		if (this.getId() == null) {
			this.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		}
		if (this.getCreateTime() == null) {
			this.setCreateTime(new Date(System.currentTimeMillis()));
		}
		if (this.getUpdateTime() == null) {
			this.setUpdateTime(new Date(System.currentTimeMillis()));
		}
		/*if(this.getCreateUserId() == null){
			this.setCreateUserId(SessionUtil.getUserId());
		}
		if(this.getUpdateUserId() == null){
			this.setCreateUserId(SessionUtil.getUserId());
		}
		if(this.getSubComId() == null){
			this.setSubComId(SessionUtil.getSubComId());
		}
		if(this.getComId() == null){
			this.setComId(SessionUtil.getComId());
		}*/
	}

	public void doBeforeUpdate() {
		if (this.getUpdateTime() == null) {
			this.setUpdateTime(new Date(System.currentTimeMillis()));
		}
		/*if(this.getUpdateUserId() == null){
			this.setCreateUserId(SessionUtil.getUserId());
		}*/
	}
}
